package com.bjsxt.item.controller;

import com.bjsxt.item.service.ItemService;
import com.bjsxt.pojo.TbItem;
import com.bjsxt.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/service/item")
public class ItemController {

    @Autowired
    private ItemService itemService;


    /**
     * 查询商品数据
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(value = "/selectTbItemAllByPage",method = RequestMethod.GET)
    public PageResult selectTbItemAllByPage(@RequestParam Integer page, @RequestParam Integer rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }

    /**
     * 商品添加
     * @param tbItem
     * @return
     */
    @RequestMapping("/insertTbItem")
    public Integer insetTbItem(@RequestBody TbItem tbItem){

        return this.itemService.insertTbItem(tbItem);
    }

    /**
     * 删除商品
     * @param tbItem
     * @return
     */
    @RequestMapping("/deleteItemById")
    public Integer deleteItemById(@RequestBody TbItem tbItem){
        return this.itemService.updateItemById(tbItem);
    }

    @RequestMapping("/preUpdateItem")
    public Map<String,Object> preUpdateItem(@RequestParam Long itemId){
      return this.itemService.preUpdateItem(itemId);
    }

    /**
     * 对商品表更新
     * @param tbItem
     * @return
     */
    @RequestMapping("/updateTbItem")
    public Integer updateTbItem(@RequestBody TbItem tbItem){

        return this.itemService.updateItemById(tbItem);
    }

    /**
     * 根据商品ID查询商品
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemInfo")
    public TbItem selectItemInfo(@RequestParam Long itemId){
        return this.itemService.selectItemInfo(itemId);
    }
}
